package com.kyecloud.dubbo.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.kyecloud.common.model.PageQuery;
import com.kyecloud.common.model.Response;
import com.kyecloud.dubbo.dto.DemoDto;
import com.kyecloud.dubbo.service.DemoDubboService;

@RestController
public class DemoRestController {
	
	private static Logger logger = LoggerFactory.getLogger(DemoRestController.class);
	
	@Reference(version = "v1.0.0",timeout=6000)
	private DemoDubboService demoDubboService;
	
	@GetMapping("/demo/{id}")
	public Response<DemoDto> findDemoById(@PathVariable Integer id){
		logger.info("Msg: 查询请求参数：{}",id);
		Response<DemoDto> result = demoDubboService.findDemoById(id);
		logger.info("Msg: 响应结果demoDto：{}",JSON.toJSONString(result));
		return result;
	}
	
	@RequestMapping("/demo/add")
	public Response<Boolean> addDemo(@RequestBody DemoDto demo){
		logger.info("Msg: 添加请求参数：{}",JSON.toJSON(demo));
		Response<Boolean> result = demoDubboService.createDemo(demo);
		logger.info("Msg: 添加响应结果：{}",JSON.toJSON(result));
		return result;
	}
	
	@RequestMapping("/demo/list")
	public Response<PageQuery<DemoDto>> demoList(@RequestBody DemoDto demo){
		logger.info("Msg: 分页查询请求参数：{}",JSON.toJSON(demo));
		Response<PageQuery<DemoDto>> result = demoDubboService.queryList(demo);
		logger.info("Msg: 分页查询响应结果：{}",JSON.toJSON(result));
		return result;
	}

}
